﻿/* 点击一个‘猫叫’按钮，弹出‘喵’的提示框 */
#pragma execution_character_set("utf-8")
#include "Widget.h"
#include "ui_widget.h"
#include <QMessageBox>
#include "Cat.h"
#include "Dog.h"
#include "Cattle.h"
#include "Sheep.h"
#include "MachineCat.h"
#include "StoneMonkey.h"
#include "IChange.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setWindowTitle("动物运动会");
}

void Widget::on_catBtn_clicked()
{
    Cat cat("小咪");
    cat.setShoutNum(5);
    QMessageBox::information(this, " ", cat.Shout());
}

void Widget::on_dogBtn_clicked()
{
    Dog dog("旺财");
    dog.setShoutNum(5);
    QMessageBox::information(this, " ", dog.Shout());
}

void Widget::on_animalRegistBtn_clicked()
{
    animalList.append(new Cat("小花"));
    animalList.append(new Dog("阿毛"));
    animalList.append(new Cattle("小黑"));
    animalList.append(new Sheep("娇娇"));
    animalList.append(new Cat("咪咪"));

    animalList.removeAt(1);
    animalList.removeAt(1);
}

void Widget::on_shoutCompareBtn_clicked()
{

    for (int i = 0; i < animalList.count(); i++) {
        QMessageBox::information(this, " ", animalList[i]->Shout());
    }
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_changeBtn_clicked()
{
    MachineCat mcat("小叮当");
    StoneMonkey wukong("孙悟空");
    QList<IChange*> array;
    array.append(&mcat);
    array.append(&wukong);

    QMessageBox::information(this, " ", array[0]->ChangeThing("各种各样的东西！"));
    QMessageBox::information(this, " ", array[1]->ChangeThing("各种各样的东西！"));
}

